package com.celer.generator;

import cn.hutool.core.bean.BeanUtil;
import com.apifan.common.random.entity.Area;
import com.celer.randomobj.Person;

import static com.celer.util.JsonUtils.toJsonStr;
import static com.celer.util.RandomUtil.areaSource;
import static com.celer.util.RandomUtil.financialSource;
import static com.celer.util.RandomUtil.internetSource;
import static com.celer.util.RandomUtil.personInfoSource;
import static com.celer.util.RandomUtil.randomAge;

public class PersonGenerator {
    public static void main(String[] args) throws Exception {
        Person person = new Person();
        generatePerson(person);
        System.out.println(toJsonStr(person));
    }

    public static void generatePerson(Person person) {
        Area area = areaSource.nextArea();
        BeanUtil.copyProperties(area, person);
        person.setAge(randomAge());
        int gender = personInfoSource.randomGender();
        if (gender == 1) {
            person.setGender("男");
            generateMale(person);
        } else {
            person.setGender("女");
            generateFemale(person);
        }
        person.setPhone(personInfoSource.randomChineseMobile());
        person.setBankNumber(financialSource.randomDebitCardNo());
        person.setEmail(internetSource.randomEmail(10));
    }

    private static void generateFemale(Person person) {
        person.setName(personInfoSource.randomFemaleChineseName());
        person.setIdNumber(personInfoSource.randomFemaleIdCard(person.getProvince(), person.getAge()));
    }



    private static void generateMale(Person person) {
        person.setName(personInfoSource.randomMaleChineseName());
        person.setIdNumber(personInfoSource.randomMaleIdCard(person.getProvince(), person.getAge()));
    }
}
